/* 封装所有存储到storage中的操作 */
const TOKEN_KEY = 'hm-news-76'
const CHANNEL_KEY = 'hm-news-channels'
const HISTORY_KEY = 'hm-news-search-history'
export function setTokenStorage (token) {
  // 注意：token是整个对象，所以必须转成json字符串才能存储
  localStorage.setItem(TOKEN_KEY, JSON.stringify(token))
}

export function getTokenStorage () {
  return JSON.parse(localStorage.getItem(TOKEN_KEY))
}

export function removeTokenStorage () {
  localStorage.removeItem(TOKEN_KEY)
}

/* 把频道保存到本地中 */
export function setChannels (channels) {
  localStorage.setItem(CHANNEL_KEY, JSON.stringify(channels))
}
/* 获取频道 */
export function getChannels () {
  return JSON.parse(localStorage.getItem(CHANNEL_KEY))
}

export function setHistory (history) {
  localStorage.setItem(HISTORY_KEY, JSON.stringify(history))
}

export function getHistory () {
  return JSON.parse(localStorage.getItem(HISTORY_KEY)) || []
}
